package io.admin.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.admin.common.constant.Constant;
import io.admin.common.page.PageData;
import io.admin.common.service.impl.CrudServiceImpl;
import io.admin.modules.log.entity.SysLogLoginEntity;
import io.admin.modules.sys.dao.EquipmentTypeDao;
import io.admin.modules.sys.dto.EquipmentTypeDTO;
import io.admin.modules.sys.entity.EquipmentTypeEntity;
import io.admin.modules.sys.service.EquipmentTypeService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 设备类型表
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2024-07-04
 */
@Service
public class EquipmentTypeServiceImpl extends CrudServiceImpl<EquipmentTypeDao, EquipmentTypeEntity, EquipmentTypeDTO> implements EquipmentTypeService {

    @Override
    public PageData<EquipmentTypeDTO> page(Map<String, Object> params) {
        IPage<EquipmentTypeEntity> page = baseDao.selectPage(
                getPage(params, Constant.CREATE_DATE, false),
                getWrapper(params)
        );
        return getPageData(page, EquipmentTypeDTO.class);
    }

    @Override
    public QueryWrapper<EquipmentTypeEntity> getWrapper(Map<String, Object> params){
        String name = (String)params.get("name");
        String state = (String)params.get("state");
        QueryWrapper<EquipmentTypeEntity> wrapper = new QueryWrapper<>();
        wrapper.like(StrUtil.isNotBlank(name), "name", name);
        wrapper.eq(StrUtil.isNotBlank(state), "state", state);
        return wrapper;
    }


}